//
//  UINavigationController+Extension.swift
//  UIKitExtentions
//
//  Created by Alean on 2023/4/10.
//

import Foundation
public extension UINavigationController {
    open class func resetNavigationBar(_ navigationBar: UINavigationBar,
                                       tintColor: UIColor = UIColor.hexString("#333333"),
                                       barTintColor: UIColor = UIColor.white,
                                       isTranslucent: Bool = false) {
        navigationBar.shadowImage = UIImage()
        navigationBar.layer.shadowColor = barTintColor.cgColor//UIColor.white.cgColor
        navigationBar.layer.shadowRadius = 20
        navigationBar.layer.shadowOpacity = 0.2
        navigationBar.layer.shadowOffset = CGSize(width: 0, height: 5)
        navigationBar.tintColor = tintColor
        navigationBar.isTranslucent = isTranslucent
        navigationBar.barTintColor = barTintColor
//        navigationBar.barStyle = .default
        navigationBar.titleTextAttributes = [
            NSAttributedString.Key.foregroundColor: tintColor,
            NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18, weight: .medium)
        ]
        if #available(iOS 13.0, *) {
            let appearance = UINavigationBarAppearance()
            appearance.configureWithOpaqueBackground()
            appearance.backgroundColor = barTintColor
            appearance.shadowImage = UIImage()
            appearance.shadowColor = nil
            appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: tintColor, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18, weight: .medium)]
            navigationBar.standardAppearance = appearance
            navigationBar.scrollEdgeAppearance = navigationBar.standardAppearance
        } else {
            let appearance = UINavigationBar.appearance()
            appearance.shadowImage = UIImage()
            appearance.layer.shadowColor = barTintColor.cgColor
            appearance.layer.shadowRadius = 20
            appearance.layer.shadowOpacity = 0.2
            appearance.layer.shadowOffset = CGSize(width: 0, height: 5)
            appearance.tintColor = tintColor //前景色，按钮颜色
            appearance.isTranslucent = isTranslucent // 导航条背景是否透明
            appearance.barTintColor = barTintColor //背景色，导航条背景色
//            appearance.barStyle = .black
            appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: tintColor, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18, weight: .medium)] // 设置导航条标题颜色，还可以设置其它文字属性，只需要在里面添加对应的属性
        }
    }

}
